package net.sf.calibur.jmx;

import javax.management.ObjectName;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.softee.management.helper.MBeanRegistration;

import static java.lang.String.*;

public class JmxRegister {	
	public static void register(ManagedBean mbean) {
		try {
			ObjectName objectName = new ObjectName(mbean.getObjectName());
			new MBeanRegistration(mbean, objectName).register();
		} catch (Exception e) {
			Logger logger = LoggerFactory.getLogger(JmxRegister.class);
			logger.error(format("Register %s as a JMX MBean failed.", mbean), e);
		}
	}

	public static void register(Object mbean, String name) {
		try {
			ObjectName objectName = new ObjectName(name);
			new MBeanRegistration(mbean, objectName).register();
		} catch (Exception e) {
			Logger logger = LoggerFactory.getLogger(JmxRegister.class);
			logger.error(
					format("Register %s by name %s as a JMX MBean failed.",
							mbean, name), e);
		}
	}
}
